<!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>投票系统后台管理</title>
  <meta name="description" content="这是一个 index 页面">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="../../../assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="../../../assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="../../../assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="../../../assets/css/admin.css">
	 <script type="text/javascript"   src="../../../js/jquery-1.11.3.min.js"></script>
	 <script type="text/javascript"  src="../../../js/cookie_util.js"></script>
	<script type="text/javascript">
		function delete_user(e){
			var username = $(e).parent().parent().parent().parent().children("td").eq(1).html();
		 	$.ajax({
    			url:"http://localhost:8080/ciic-vote/user/deleteUser.do",
    			type:"post",
    			data:{"username":username},
    			dataType:"json",
    			success:function(result){
    				if(result.status == 0){
						alert("删除用户及活动成功");
						window.location.href="findAll.html";
    				}
    			}
    		});			
		}
		function modify_pwd(e){
			var username_modify = $(e).parent().parent().parent().parent().children("td").eq(1).html();
			addCookie("username_modify",username_modify,2);
			window.location.href="modify_pwd.html";
		}
		
		function load_acivity(e){
			var creatorId = $(e).parent().parent().parent().parent().children("td").eq(0).html();
			addCookie("creatorId",creatorId,2);
			window.location.href="load_activity.html";
		}
	 	$(function(){
		 	$.ajax({
    			url:"http://localhost:8080/ciic-vote/user/findAll.do",
    			type:"post",
    			dataType:"json",
    			success:function(result){
    				if(result.status == 0){
 				var list = result.data;
    					for(var i=0; i<list.length; i++){
    						var userName = list[i].username;
    						var role = list[i].role;
    						var roleStr = null;
    						if(role==0){
    							roleStr = "超级管理员";
    						}
    						if(role==1){
    							roleStr = "管理员";
    						}
    						var id = list[i].id;
    						
        					var li = '<tr><td>';
        					li += id;
        					li += '</td><td>';
        					li += userName;
        					li += '</td><td>';
        					li += roleStr;
        					li += '</td><td>';
        	                li +=  '<div class="am-btn-toolbar">';
        	                li +=    '<div class="am-btn-group am-btn-group-xs">';
        	                li +=      '<button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="modify_pwd(this)"><span class="am-icon-pencil-square-o"></span> 修改密码</button>';
        	                li +=      '<button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="load_acivity(this)"><span class="am-icon-pencil-square-o"></span> 查看活动</button>';
        	                li +=      '<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="delete_user(this)"><span class="am-icon-trash-o"></span> 删除</button>';
        	                li +=    '</div>';
        	                li +=  '</div>';
        					li += '</td>';
        					li += '</tr>';
        					li = $(li);
    						$("#user_list").append(li);
    					}
    				}
    			}
    		});
    		
	 	});
	 </script>
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar am-topbar-inverse admin-header">
  <div class="am-topbar-brand">
    <strong>投票系统</strong> <small>后台管理</small>
  </div>

  <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

  <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

    <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
      <li class="am-dropdown" data-am-dropdown>
        <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
          <span class="am-icon-users"></span> <span id="userName"></span> <span class="am-icon-caret-down"></span>
        </a>
        <ul class="am-dropdown-content">
          <li><a href="javascript:void(0)" onclick="exit();"><span class="am-icon-power-off"></span> 退出</a></li>
        </ul>
      </li>
      <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>
    </ul>
  </div>
</header>

<div class="am-cf admin-main">
  <!-- sidebar start -->
  <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
    <div class="am-offcanvas-bar admin-offcanvas-bar">
      <ul class="am-list admin-sidebar-list">
        <li><a href="success.html"><span class="am-icon-home"></span> 首页</a></li>
        <li class="admin-parent">
          <a class="am-cf" data-am-collapse="{target: '#collapse-nav'}"><span class="am-icon-file"></span> 用户管理 <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
          <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-nav">
            <li><a href="create_user.html" class="am-cf"><span class="am-icon-check"></span> 创建用户<span class="am-icon-star am-fr am-margin-right admin-icon-yellow"></span></a></li>
            <li><a href="findAll.html"><span class="am-icon-puzzle-piece"></span> 查看用户</a></li>
          </ul>
        </li>
        <li class="admin-parent">
          <a class="am-cf" data-am-collapse="{target: '#collapse-nav2'}"><span class="am-icon-file"></span> 活动管理 <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
          <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-nav2">
            <li><a href="../../activity/super/create_activity.html" class="am-cf"><span class="am-icon-check"></span> 创建活动<span class="am-icon-star am-fr am-margin-right admin-icon-yellow"></span></a></li>
            <li><a href="../../activity/super/findAll.html"><span class="am-icon-puzzle-piece"></span> 查看活动</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong> / <small>用户列表</small></div>
      </div>
      
      <div class="am-g">
        <div class="am-u-sm-12">
        
          <table class="am-table am-table-bd am-table-striped admin-content-table">
           
            <thead>
            <tr>
              <th>ID</th><th>用户名</th><th>角色</th><th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;管理</th>
            </tr>
            </thead>
            
            <tbody id="user_list">
            </tbody>
          </table>
        </div>
      </div>
    </div>

    <footer class="admin-content-footer">
      <hr>
      <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>
  </div>
  <!-- content end -->

</div>

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="../../../assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="../../../assets/js/amazeui.min.js"></script>
<script src="../../../assets/js/app.js"></script>
<script src="../../../js/exit_and_showname.js"></script>
</body>
</html>
